package cn.jekun.shop.web.bean;

import java.util.List;

import javax.servlet.http.HttpSessionBindingEvent;

import cn.jekun.component.base.bean.SessionUser;
import cn.jekun.component.base.spring.SpringUtils;
import cn.jekun.component.core.service.LogService;
import cn.jekun.shop.common.service.CartService;
import cn.jekun.web.shop.bean.UserLogin;
import cn.jekun.web.shop.bean.UserShops;
/**
 * 會員登錄后相關信息記錄在memberSession中
 * @author twj
 *
 */
@SuppressWarnings("serial")
public class MemberSession extends SessionUser{
	private String userName;
	private String shopId;
	private String mobile;
	private String memberId;
	private String shopName;
	private String shopPrintType;
	private String agentId; //当前代理商代码
	private String agentName;//代理商名称
	private String agentMobile;//代理商电话
	private List<UserShops> userShops; // 商家(分店列表)
	
	private String shopMobile; //当前商家手机号码

	private UserLogin loginlogs; //商家登录

	private String iconUrl;
	
	private String pwd;
	
	
	
	public String getAgentMobile() {
		return agentMobile;
	}
	public void setAgentMobile(String agentMobile) {
		this.agentMobile = agentMobile;
	}
	public String getAgentName() {
		return agentName;
	}
	public void setAgentName(String agentName) {
		this.agentName = agentName;
	}
	public String getAgentId() {
		return agentId;
	}
	public void setAgentId(String agentId) {
		this.agentId = agentId;
	}
	public String getShopPrintType() {
		return shopPrintType;
	}
	public void setShopPrintType(String shopPrintType) {
		this.shopPrintType = shopPrintType;
	}
	public String getIconUrl() {
		return iconUrl;
	}
	public void setIconUrl(String iconUrl) {
		this.iconUrl = iconUrl;
	}
	public UserLogin getLoginlogs() {
		return loginlogs;
	}
	public void setLoginlogs(UserLogin loginlogs) {
		this.loginlogs = loginlogs;
	}
	public String getShopMobile() {
		return shopMobile;
	}
	public void setShopMobile(String shopMobile) {
		this.shopMobile = shopMobile;
	}
	public List<UserShops> getUserShops() {
		return userShops;
	}
	public void setUserShops(List<UserShops> userShops) {
		this.userShops = userShops;
	}
	public String getShopName() {
		return shopName;
	}
	public void setShopName(String shopName) {
		this.shopName = shopName;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getShopId() {
		return shopId;
	}
	public void setShopId(String shopId) {
		this.shopId = shopId;
	}
	public String getMobile() {
		return mobile;
	}
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	public String getMemberId() {
		return memberId;
	}
	public void setMemberId(String memberId) {
		this.memberId = memberId;
	}
	
	public String getPwd() {
		return pwd;
	}
	public void setPwd(String pwd) {
		this.pwd = pwd;
	}
	@Override
	protected void afterLogin(HttpSessionBindingEvent event) {
		super.afterLogin(event);
		//把购物车里的临时商品转给该用户
		try {
			CartService cartService = SpringUtils.getBean(CartService.BEAN_NAME);
			cartService.changeTempGoodsToUser(this.getUserId(),event.getSession().getId());
		} catch (Exception e) {
			e.printStackTrace();
		}
		//记录登录日志
		try{
			LogService logService = SpringUtils.getBean(LogService.BEAN_NAME);
			logService.addMallLog(this.getUserId(), this.getBrowser(), this.getIp(),"商城用户登录系统");
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	@Override
	protected void afterLogout(HttpSessionBindingEvent event) {
		super.afterLogout(event);
		//记录退出日志
		try{
			if(this.getUserId()!=null){
				LogService logService = SpringUtils.getBean(LogService.BEAN_NAME);
				logService.addMallLog(this.getUserId(), this.getBrowser(), this.getIp(),"商城用户退出系统");
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
}
